<?php

namespace App\Admin\Controllers;

use App\Models\Order;

use App\Scopes\OrderScope;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class OrderController extends Controller
{
    use ModelForm;

    protected $header = '订单管理';
    protected $description = '管理所有订单';

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description($this->description);

            $content->body($this->grid());
        });
    }

    public function show(Order $order)
    {
        return Admin::content(function (Content $content) use($order) {

            $content->header($this->header);
            $content->description($this->description);

            $content->body(view('admin.orders.show', compact('order')));
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Order::class, function (Grid $grid) {
            $grid->user()->name('用户');
            $grid->out_trade_no('订单号');
            $grid->status('订单状态');
            $grid->regund_status('退款状态');
            $grid->created_at();
            $grid->filter(function ($filter) {
                $filter->disableIdFilter();
            });
        });
    }
}
